.PHONY: build clean run show_tag docker_build docker_push docker_upload

export DATE=`date "+%Y-%m-%d"`

docker_push: docker_build docker_upload

build:
	@ ./script/build.sh

clean:
	@ rm ./out/*

run:
	@ ./script/run.sh

show_tag:
	@ echo simple_updater_dev:$(VERSION).$(DATE)

docker_build: build
	# Change tag
	sed -i s/latest/$(VERSION).$(DATE)/g ./docker-compose.yml
	# Start Build
	docker compose build --no-cache
	# Change back
	sed -i s/$(VERSION).$(DATE)/latest/g ./docker-compose.yml
	# docker buildx build . --build-arg BUILD_TYPE=release -t simple_updater_dev:$(VERSION).$(DATE)

docker_upload:
	mkdir -p ./cache
	rm -rf ./cache/*
	docker save -o ./cache/simple_updater_dev.tar simple_updater_dev:$(VERSION).$(DATE)
	cp ./script/update.sh ./cache/update.sh
	cp ./docker-compose.yml ./cache/docker-compose.yml
	# chmod +x ./script/update.sh
	sed -i 's/\/release:/:/g' ./cache/docker-compose.yml
	sed -i s/latest/$(VERSION).$(DATE)/g ./cache/docker-compose.yml
	sed -i s/TARGET_IMAGE_TAG/$(VERSION).$(DATE)/g ./cache/update.sh
	sed -i s/VERSION_ID/$(VERSION_ID)/g ./cache/docker-compose.yml
	sed -i s/VERSION_ID/$(VERSION_ID)/g ./cache/update.sh
	# Use rsync to enhance
	scp -r ./cache/* $(REMOTE)
	rm -rf ./cache
